<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('【请填写功能名称】列表')" />
    <th:block th:include="include :: datetimepicker-css"/>
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form action="#" th:action="@{/labappointment/addlists}" th:object="${labInfo}" method="post">
                    <div class="select-list">
                        <ul>
                            <li>
                                <div style="display: flex;">
                                    <span>实验室名称：</span>
                                    <select th:field="*{labId}" class="form-control m-b" th:with="type=${@lab.getType()}" style="width:220px;height:32px;">
                                        <option value="" th:text="${#lists.isEmpty(type)?'实验室全部关闭或未添加':'请选择'}"></option>
                                        <option th:each="lab : ${type}" th:text="${lab.labName}" th:value="${lab.id}" required></option>
                                    </select>
                                </div>
                            </li>
                            <li>
                                <div style="display: flex;">
                                    <span>预约时间：</span>
                                    <div class="input-group date">
                                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                        <input th:field="*{experimentDate}" class="form-control" id="datetimepicker-demo-2" placeholder="yyyy-MM-dd">
                                    </div>
                                </div>
                            </li>
                            <li>
                                <div style="display: flex;">
                                    <span>备注：</span>
                                    <div class="input-group date">
                                        <input name="remark" class="form-control" id="remark">
                                    </div>
                                </div>
                            </li>
                            <li>
<!--                                <input type="submit" value="搜索">-->
                                <button class="btn btn-primary" type="submit">搜索</button>
                                <!--<a class="btn btn-primary btn-rounded btn-sm"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()" ><i class="fa fa-refresh"></i>&nbsp;重置</a>-->
                                <button type="button" class="btn btn-w-m btn-success" style="position: relative;left:40%;" onclick="apply()">申请</button>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>


            <div class="col-sm-12 select-table table-striped">
                <div th:if="not ${#lists.isEmpty(addList)}">
                <table id="table" class="table">
                    <thead>
<!--                    <tr th:each="add:${addList}">-->
                        <th th:text="节次"><input type="hidden" id="labId" value="${addList[0].secDate}"></th>
                        <th th:text="${addList[0].secDate}"></th>
                        <th th:text="${addList[1].twoDays}"></th>
                        <th th:text="${addList[2].threeDays}"></th>
                        <th th:text="${addList[3].fourDays}"></th>
                        <th th:text="${addList[4].fiveDays}"></th>
<!--                    </tr>-->
                    </thead>
                    <tbody>
                    <tr th:each="add:${addList}">
                        <td th:text="'第'+${add.section}+'节'"></td>
                        <td th:switch="${add.oneDay}">
                        <span th:case="'0'"><input type="checkbox" disabled>未开放</span>
                        <span th:case="'1'"><input type="checkbox" disabled>已被预约</span>
                        <span th:case="'2'"><input type="checkbox" th:value="${add.section}+${addList[0].secDate}">开放中</span>
                        </td>
<!--                        <td th:text="${addlist.oneDay}"></td>-->
                        <td th:switch="${add.twoDay}">
                            <span th:case="'0'"><input type="checkbox" disabled>未开放</span>
                            <span th:case="'1'"><input type="checkbox" disabled>已被预约</span>
                            <span th:case="'2'"><input type="checkbox" th:value="${add.section}+${addList[1].twoDays}">开放中</span>
                        </td>
                        <td th:switch="${add.threeDay}">
                            <span th:case="'0'"><input type="checkbox" disabled>未开放</span>
                            <span th:case="'1'"><input type="checkbox" disabled>已被预约</span>
                            <span th:case="'2'"><input type="checkbox" th:value="${add.section}+${addList[2].threeDays}">开放中</span>
                        </td>
                        <td th:switch="${add.fourDay}">
                            <span th:case="'0'"><input type="checkbox" disabled>未开放</span>
                            <span th:case="'1'"><input type="checkbox" disabled>已被预约</span>
                            <span th:case="'2'"><input type="checkbox" th:value="${add.section}+${addList[3].fourDays}">开放中</span>
                        </td>
                        <td th:switch="${add.fiveDay}">
                            <span th:case="'0'"><input type="checkbox" disabled>未开放</span>
                            <span th:case="'1'"><input type="checkbox" disabled>已被预约</span>
                            <span th:case="'2'"><input type="checkbox" th:value="${add.section}+${addList[4].fiveDays}">开放中</span>
                        </td>
                    </tr>
                    </tbody>
                </table>

                </div>
                <div th:if="${#lists.isEmpty(addList)}">
                    <table id="bootstrap-table" class="table">
                        <th style="text-align: center">该实验室暂未发布数据</th>
                    </table>
                </div>
            </div>

            <!--<div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>-->
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:labappointment:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:labappointment:remove')}]];
        var prefix = ctx + "labappointment";

        function apply(){
            //$('input:checkbox:checked') 等同于 $('input[type=checkbox]:checked')
            //意思是选择被选中的checkbox
            var number=0;
            var applyParam =new Array();
            $.each($('input:checkbox:checked'),function(){
                number=$('input[type=checkbox]:checked').length;
                // window.alert("你选了："+$('input[type=checkbox]:checked').length+"个，其中有："+$(this).val());
                var labId=$("#labId").val();
                applyParam.push({'applyTime':$(this).val().substring(1,$(this).val().length),"section":$(this).val().substring(0,1),"labId":labId,"remark":$('#remark').val()});
            });
            if(number==0){
                $.modal.msgError("请选择")
                return false;
            }
            $.modal.confirm("确认要申请选中的" + number+ "条数据吗?", function() {
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    contentType:"application/json;charset=utf-8",
                    url: prefix + "/apply",
                    data: JSON.stringify(applyParam),
                    cache: false,
                    async: true,
                    success: function (data) {
                        if(data.code==500){
                            $.modal.msgError(data.msg)
                        }
                        if(data.code==0){
                            $.modal.msgSuccess(data.msg)
                            var int=self.setInterval(function(){  // 这个方法是说在延迟两秒后执行大括号里的方法
                                $.modal.reload();
                            },1000) //这里2000代表两秒

                        }
                        // $.modal.msgReload()
                    }
                });
            });
        }

        function search(id){
            var url = prefix + '/addlist' ;
            $.modal.openTab("实验室预约", url);
        }
        $("#datetimepicker-demo-2").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });


    </script>
</body>
</html>